﻿/*
 * Last review by   : Yaser
 * Last review date : JUL-25-09 
 */
using System;
using ERP.Framework.Components.Utilities.TracingHelper;

namespace ERP.Framework.Components.Utilities.EnumHelper
{
    /// <summary>
    /// Enum localizer reads a localized string from Resx file for Enum values
    /// </summary>
    public abstract class Localizer
    {
        #region Members

        private const string TRACING_CATEGORY = "ERP.Framework.Components.EnumHelper.Localizer";

        #endregion

        #region Methods

        /// <summary>
        /// Gets the localized string.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        public static string GetLocalizedString(Enum value)
        {
            TraceUtil.Write(TRACING_CATEGORY, "GetLocalizedString : Start");
            TraceUtil.Write(TRACING_CATEGORY, string.Format("GetLocalizedString : value: {0}", value.ToString()));
            System.Resources.ResourceManager x = new System.Resources.ResourceManager(value.GetType());
            TraceUtil.Write(TRACING_CATEGORY, "GetLocalizedString : End");
            return x.GetString(value.ToString());
        }

        #endregion
    }

    /// <summary>
    /// Extension methods for Enum
    /// </summary>
    public static class EnumExtender
    {
        #region Methods

        /// <summary>
        /// Translates the specified value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        public static string Translate(this Enum value)
        {
            return Localizer.GetLocalizedString(value);
        }

        #endregion
    }
}
